/*
 * File      : board.h
 * This file is part of RT-Thread RTOS
 * COPYRIGHT (C) 2009, RT-Thread Development Team
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rt-thread.org/license/LICENSE
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-09-09     WCH        the first version
 */

// <<< Use Configuration Wizard in Context Menu >>>
#ifndef __BOARD_H__
#define __BOARD_H__

#include "ch32v30x.h"
#include <rtthread.h>
#include <rthw.h>

/* board configuration */
//#define SRAM_SIZE  128
//#define SRAM_END (0x20000000 + SRAM_SIZE * 1024)

//extern int _ebss;
//extern int _stack_size;             // the stack size of main?
//#define HEAP_BEGIN  ((void *)&_ebss)
//#define HEAP_END    ((void *)(SRAM_END-_stack_size))
//#define HEAP_END    (SRAM_END)

/*-------------------------- ROM/RAM CONFIG BEGIN --------------------------*/
#define ROM_START               ((uint32_t)0x08000000)
#define ROM_SIZE                (192 * 1024)
#define ROM_END                 ((uint32_t)(ROM_START + ROM_SIZE))

#define RAM_START               (0x20000000)
#define RAM_SIZE                (128 * 1024)
#define RAM_END                 (RAM_START + RAM_SIZE)

/*--------------------------     GET HEAP SIZE    --------------------------*/
#if defined(__CC_ARM) || defined(__CLANG_ARM)
extern int Image$$RW_IRAM1$$ZI$$Limit;
#define HEAP_BEGIN      ((void *)&Image$$RW_IRAM1$$ZI$$Limit)
#elif __ICCARM__
#pragma section="CSTACK"
#define HEAP_BEGIN      (__segment_end("CSTACK"))
#else
extern rt_ubase_t end;
#define HEAP_BEGIN      ((void *)&end)          /* both available */
#endif
extern rt_ubase_t _susrstack;
#define HEAP_END        ((void *)&_susrstack)




//extern volatile unsigned long  interrupter_sp_saver;
void rt_hw_board_init(void);
void rt_hw_us_delay(rt_uint32_t us);


#endif /* __BOARD_H__ */
